﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for cUIUtili
/// </summary>
public class cUIUtili
{
    public cUIUtili()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public static System.Web.UI.WebControls.ListItemCollection getResourceComboItem(string loggedUserName)
    {
        System.Web.UI.WebControls.ListItemCollection lic = new System.Web.UI.WebControls.ListItemCollection();
        string sSql = "SELECT AppsLogin.ResourceId, AppsLogin.UserName, AppsLogin.Role, Resources.Description, Resources.Status FROM (AppsLogin LEFT OUTER JOIN Resources ON AppsLogin.ResourceId = Resources.ResourceId) WHERE Resources.Status = 0;";
        string sRole = string.Empty;
        try
        {
            System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            System.Data.OleDb.OleDbCommand cm = new System.Data.OleDb.OleDbCommand(sSql, cn);
            cn.Open();
            System.Data.OleDb.OleDbDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                sRole = (dr.IsDBNull(2) ? string.Empty : dr.GetString(2));
                if ((dr.GetString(1) == loggedUserName) && (sRole != "ADMIN"))
                {
                    lic.Clear();
                    lic.Add(new System.Web.UI.WebControls.ListItem(dr.GetString(3), dr.GetGuid(0).ToString("B")));
                    break;
                }
                else
                {
                    lic.Add(new System.Web.UI.WebControls.ListItem(dr.GetString(3), dr.GetGuid(0).ToString("B")));
                }
            }
            dr.Close();
            cn.Close();
        }
        catch (System.Data.OleDb.OleDbException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw e;
        }
        return lic;
    }


}
